<?php namespace App\Http\Middleware;

use App\Http\Models\User;
use App\Http\Models\WebChat;
use Closure;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;

class BaseMiddleware
{

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!Session::get('CWebChatID')) {
            $webUser = WebChat::getUser();
            if (!isset($webUser->openid)) {
                die('Access Denied3!');
            }
            Session::put('CWebChatID', $webUser->openid);
            Session::put('CName', $webUser->nickname);
            $data['CWebChatID'] = $webUser->openid;
        }
        return $next($request);
    }

}
